iT邦幫忙

2024 iThome 鐵人賽

DAY 26
0
Security

密碼學小白的學習之路系列 第 26

[Day 26] 題目(Network Attacks )

  • 分享至 

  • xImage
  •  

今天先來寫challenge的兩題,剛回到家發現Symmetric-10的題目有點小複雜...所以明天再解!
首先是Introduction的Network Attacks這題。

Network Attacks

https://cryptohack.org/challenges/introduction/
https://ithelp.ithome.com.tw/upload/images/20240901/20168165ivC3aCfqAH.png

題意:

我們需要連接到socket.cryptohack.org的11112端口,然後發送一個包含buy鍵和flag值的JSON物件。

題目給的程式碼與註解:

from pwn import * 
import json  
# 定義伺服器的主機名和端口號
HOST = "socket.cryptohack.org"
PORT = 11112
r = remote(HOST, PORT) # 創建一個與遠端伺服器的連接,使用 HOST 和 PORT 參數
def json_recv(): # 接收伺服器 JSON 回應的函式
    line = r.readline()  # 從伺服器讀取一行數據
    return json.loads(line.decode())  # 將接收到的數據解碼並轉換為 JSON 格式(Python 字典)

def json_send(hsh): # 向伺服器發送 JSON 請求的函式
    request = json.dumps(hsh).encode()  # 將 Python 字典轉換為 JSON 字符串,並編碼為二進位格式
    r.sendline(request)  # 將編碼後的請求發送給伺服器

# 依次讀取並打印來自伺服器的四行初始訊息
print(r.readline())  
print(r.readline()) 
print(r.readline()) 
print(r.readline()) 

# 創建一個要發送給伺服器的請求,表示想要購買「clothes」
request = {
    "buy": "clothes"
}
json_send(request)  # 將請求發送給伺服器
response = json_recv() # 接收伺服器的回應,並將其轉換為 Python 字典格式
print(response)

解法:

我們可以看到程式碼中有這麼一行

request = {
    "buy": "clothes"
}

而題目告訴我們要buy flags,所以我們把clothes改成flags。

request = {
    "buy": "flag"
}

執行程式碼後會得到:

b"Welcome to netcat's flag shop!\n"
b'What would you like to buy?\n'
b"I only speak JSON, I hope that's ok.\n"
b'\n'
{'flag': 'crypto{sh0pp1ng_f0r_fl4g5}'}

crypto{sh0pp1ng_f0r_fl4g5}

先這樣,繼續更新文章中~


上一篇
[Day 25] 題目(Symmetric-9)
下一篇
[Day 27] 題目(Encoding Challenge) & 凱薩密碼與 rot 13
系列文
密碼學小白的學習之路31
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言